from app.commons.db import db
from app.commons.ma import ma
from ..base import Base
import time


class StockInfo(Base, db.Model):
    id = db.Column(db.Integer, nullable=False, primary_key=True)
    name = db.Column(db.String(127), nullable=False)
    quick_price = db.Column(db.String(127), nullable=False)
    ctime = db.Column(db.Integer, nullable=False, default=int(time.time()))
    mtime = db.Column(db.Integer, nullable=False, default=int(time.time()), onupdate=int(time.time()))
    deleted = db.Column(db.Integer, nullable=False, default=0)

    @classmethod
    def find_all_by_not_deleted(cls):
        return cls.query.filter_by(deleted=0).all()


class StockInfoSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = StockInfo


stockinfo_schema = StockInfoSchema()
